home *** CD-ROM | disk | FTP | other *** search
/ Visual Basic Source Code / Visual Basic Source Code.iso / vbsource / rdblib / rdbfrmcd.bas < prev    next >
BASIC Source File  |  1995-05-09  |  3KB  |  91 lines

  1. ' This module contains sample code that must be placed in forms
  2. ' This is necessary because the routines reference controls on the form
  3. ' To use these routines:
  4. '   add this module to the project
  5. '   copy the desired routines to your form code
  6. '   remove this module from the project (this code will create errors if included)
  7. '
  8. ' The routines present are:
  9. '   FldGotFocus: highlights a field and displays help in cmsg control
  10. '       to use add following in GotFocus event FldGotFocus control-name
  11. '   FldLostFocus: removes highlight from a field and removes help in cmsg control
  12. '       to use add following in LostFocus event FldLostFocus control-name
  13. '   ShowHelp: displays popup help for a control (button, etc)
  14. '       to use add following in MouseMove event ShowHelp control-name, x, y
  15. '       in events that perform action, e.g. Click add ShowHelp control-name, 0, 0
  16. '
  17. ' See the routines for additional information
  18. '
  19. ' Provided courtesy of RDB Systems, Royce D. Bacon.
  20. ' Compuserve Id: 70042,1001
  21. ' You are free to use these routines in any way you desire
  22. ' Of course, I'm not responsible for the results
  23. '
  24.  
  25. Sub FldGotFocus (PControl As Control)
  26.     PControl.BackColor = BLUE
  27.     PControl.ForeColor = WHITE
  28.     PControl.SelStart = 0
  29.     PControl.SelLength = 1000
  30.     cmsg.Caption = PControl.Tag
  31.  
  32. End Sub
  33.  
  34. Sub FldLostFocus (PControl As Control)
  35.     PControl.BackColor = RB_GRAY
  36.     PControl.ForeColor = BLACK
  37.     cmsg.Caption = ""
  38.  
  39. End Sub
  40.  
  41. Sub ShowHelp (PBtn As Control, px As Single, py As Single)
  42. ' Subroutine to show popup help for a control
  43. ' To use:
  44. '    add a panel control called PnlHelp to the form
  45. '    Set control's tag property to help message desired
  46. '    Copy this subroutine to the form code
  47. '    In mousemove event of control add
  48. '       ShowHelp control-name, x, y
  49. '    In click event or other events of control that cause action add
  50. '       ShowHelp control-name, 0, 0     ' Hides help
  51.  
  52.     Dim maxx As Single, maxy As Single
  53.     Dim nPnlTop As Single, nPnlLeft As Single
  54.     ' Determine max x & y coordinates with 80 twip border
  55.     ' boundry of 80 twips allowed to be able to catch cursor as exiting control
  56.     maxx = PBtn.Width - 80
  57.     maxy = PBtn.Height - 80
  58.     ' if exiting control area turn off help panel
  59.     If px < 80 Or py < 80 Or px > maxx Or py > maxy Then
  60.         PnlHelp.Visible = False
  61.         PnlHelp.Caption = ""
  62.         Exit Sub
  63.     End If
  64.  
  65.     ' Determine location for help panel
  66.     ' Assume below and to right
  67.     nPnlTop = PBtn.Top + PBtn.Height + 40
  68.     nPnlLeft = PBtn.Left + 100
  69.     ' Put panel above control if not enough room below
  70.     If nPnlTop + PnlHelp.Height > Height - 1024 Then
  71.         nPnlTop = PBtn.Top - PnlHelp.Height - 40
  72.     End If
  73.     ' Put panel to left if not enough room to right
  74.     If nPnlLeft + PnlHelp.Width > Width - 500 Then
  75.         nPnlLeft = PBtn.Left + PBtn.Width - 40
  76.     End If
  77.  
  78.     ' if same settings exit to prevent flickering effect
  79.     If PnlHelp.Caption = PBtn.Tag And PnlHelp.Top = nPnlTop And PnlHelp.Left = nPnlLeft Then
  80.         Exit Sub
  81.     End If
  82.     
  83.     ' get help msg from control's tag and position help panel
  84.     PnlHelp.Caption = PBtn.Tag
  85.     PnlHelp.Top = nPnlTop
  86.     PnlHelp.Left = nPnlLeft
  87.     PnlHelp.Visible = True
  88.     
  89. End Sub
  90.  
  91.